package com.lf.cloud.comm.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.lf.cloud.comm.modal.pojo.BlogContent;
import com.lf.cloud.comm.webutils.CommMethod;

public class BlogContentDao extends BlogContent {
	
	
	public static BlogContentDao me = new BlogContentDao();
	
	
	public static String tabName = CommMethod.getTbaleName("BlogContent");
	
	
	public boolean insertBlogContent(BlogContent blogContent){
		return blogContent.save();
	}
	public boolean updateBlogContent(BlogContent blogContent){
		return blogContent.update();
	}

	
	
	public void insertBatchBlogContent(List<BlogContent> blogContent , int batchSize ){
		Db.batchSave(blogContent, batchSize);
	}
	
	
	  
	/**  
	* @Title: geetBlogContentById  
	* @Description: 查询详细内容  
	* @param @param id
	* @param @return
	* @return BlogContent
	* @author lxliufei
	* @date 下午6:28:05
	* @throws  
	*/  
	public BlogContent geetBlogContentById(String id){
		return dao.findById(id);
	}
	
	
	  
	/**  
	* @Title: getBlogContentPage  
	* @Description: 分页查询  
	* @param @param pageNumber
	* @param @param pageSize
	* @param @param tagNo
	* @param @return
	* @return Page<BlogContent>
	* @author lxliufei
	* @date 下午6:33:53
	* @throws  
	*/  
	    
	public Page<BlogContent> geetBlogContentPage(int pageNumber , int pageSize , String tagName ){
		String selectStr = " SELECT * ";
		String sql = " FROM  "+ tabName + " WHERE 1=1 ";
		if(StringUtils.isNotEmpty(tagName)){
			sql += " AND blog_title LIKE '%"+tagName+"%' ";
		}
		sql += " ORDER BY update_time desc ";
		return dao.paginate(pageNumber, pageSize, selectStr, sql);
	}
	
	
	public List<BlogContent> geetBlogContent_GroupBy(String tagName ){
		String sql = "SELECT * FROM  "+ tabName + " WHERE 1=1 ";
		if(StringUtils.isNotEmpty(tagName)){
			sql += " AND blog_title LIKE '%"+tagName+"%' ";
		}
		sql += " ORDER BY update_time desc ";
		System.out.println(sql);
		return dao.find(sql);
	}
	
	
	
	
	
	
	
	

}
